import React, {Component} from 'react';

class
State
extends
Component
{
    state={
        count:1
    }
    render()
    {
        return (
            <div>
                {this.state.count}
                <button onClick={this.handleClick_add.bind(this)}>add</button>
                <button onClick={this.handleClick_add2}>add2</button>
            </div>
        );
    }
    handleClick_add(){
        // let count=this.state.count;
        // count+=1;
        this.setState({
            count: this.state.count+1
        })
        console.log(this.state.count)
        this.setState({
            count: this.state.count+1
        })
        console.log(this.state.count)
    }
    handleClick_add2=()=>{
        // let count=this.state.count;
        // count+=1;
       setTimeout(()=>{
           this.setState({ 
               count: this.state.count+1
           })
           console.log(this.state.count)
           this.setState({
               count: this.state.count+1
           })
           console.log(this.state.count)
           this.setState({
               count: this.state.count+1
           })
           console.log(this.state.count)
       },0)
    }
}/*
setState在处于同步状态时使用异步更新，来更新DOM
setState处于异步状态时使用同步步更新，来更新DOM

*/

export default State;
